package com.lmy.springboot_rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 死信队列(当消息被拒绝、消息过期、队列长度不够时，消息会进入死信队列)
 */
@Configuration
public class DeadRabbitmqConfiguration {

    //1.声明注册direct模式交换机
    @Bean
    public DirectExchange deadDirectExchange() {
        return new DirectExchange("dead_direct_order_exchange");
    }

    //2.声明队列
    @Bean
    public Queue deadQueue() {
        return new Queue("dead_order_queue", true, false, false);
    }

    //3.绑定关系
    @Bean
    public Binding deadDirectBinding() {
        return BindingBuilder.bind(deadQueue()).to(deadDirectExchange()).with("dead");
    }
}
